﻿using System;
using System.ComponentModel;
using System.Net.Mail;
using System.Workflow.ComponentModel;

namespace Argos.Activities.MessageDelivery
{
	[Description("A message delivery activity that sends a message by e-mail.")]
	public class EmailDeliveryActivity : MessageDeliveryActivityBase
	{

		protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
		{
			MailAddress to = new MailAddress(this.Message.RecipientAddress, this.Message.RecipientName);
			using (MailMessage msg = new MailMessage())
			{
				msg.To.Add(to);
				msg.Subject = this.Message.Subject;
				msg.Body = this.Message.Body;
				msg.IsBodyHtml = string.Equals(this.Message.BodyContentType, System.Net.Mime.MediaTypeNames.Text.Html, StringComparison.OrdinalIgnoreCase);

				SmtpClient client = new SmtpClient();
				client.Send(msg);
			}

			return ActivityExecutionStatus.Closed;
		}
	}
}
